﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using pay.Entity;
using System.Data.SqlClient;

namespace pay.DAL
{
    public class OrderDetailDAL
    {
        /// <summary>
        /// Web_OrderDetail对象的添加方法
        /// </summary>
        /// <param name="t">Web_OrderDetail实体对象</param>
        /// <returns>数据库影响行数</returns>
        public int Add(OrderDetail t)
        {
            try
            {
                Tools tool = new Tools();
                
                tool.AddSqlParameter("id", SqlDbType.Int, 4, t.Id);
                tool.AddSqlParameter("ordernumber", SqlDbType.VarChar, 30, t.Ordernumber);
                tool.AddSqlParameter("productid", SqlDbType.Int, 4, t.Productid);
                tool.AddSqlParameter("num", SqlDbType.Int, 4, t.Num);
                tool.AddSqlParameter("singleprice", SqlDbType.Money, 8, t.Singleprice);
                tool.AddSqlParameter("isonline", SqlDbType.TinyInt, 1, t.Isonline);
                tool.AddSqlParameter("nowprice", SqlDbType.Money, 8, t.Nowprice);
                tool.AddSqlParameter("issell", SqlDbType.VarChar, 2, t.Issell);
                return Emoney.DataAccess.SqlHelper.ExecuteNonQuery(DBConn.Con_Etone, CommandType.StoredProcedure, "Web_OrderDetail_Add", tool.GetSqlParameters());
            }
            catch (Exception ex)
            {

               
                //LogYuMin.LogWriter.GetWriter(LogYuMin.LogFile.Log).Write(GetType(), "Add", LogYuMin.LogStates.ERROR, ex);
          
                
                return 0;
            }
           
        }

        public List<OrderDetails> GetOrderDetailByID(OrderQuery query)
        {
            Tools tool = new Tools();
            List<OrderDetails> list = new List<OrderDetails>();
            tool.AddSqlParameter("ordernumber", SqlDbType.VarChar, 50, query.OrderNumber);
            SqlConnection con = new SqlConnection(DBConn.Con_emweb_new);
            con.Open();
            SqlDataReader reader = Emoney.DataAccess.SqlHelper.ExecuteReader(con, CommandType.StoredProcedure, "Web_OrderDetail_ByID", tool.GetSqlParameters());
            OrderDetails m = null;
            try
            {
                while (reader.Read())
                {
                    m = new OrderDetails();
                    m.Id = Tools.GetInt(reader["id"]);
                    m.Ordernumber = Tools.GetString(reader["ordernumber"]);
                    m.Productid = Tools.GetInt(reader["productid"]);
                    m.Num = Tools.GetInt(reader["num"]);
                    m.Singleprice = Tools.GetDouble(reader["singleprice"]);
                    m.Isonline = Tools.GetInt(reader["isonline"]);
                    m.Nowprice = Tools.GetDouble(reader["nowprice"]);
                    m.Issell = Tools.GetString(reader["issell"]);
                    m.Productname = Tools.GetString(reader["productname"]);
                    m.Allmoney = Tools.GetDouble(reader["allmoney"]);
                    list.Add(m);
                    
                }
                return list;
            }
            catch (Exception ex)
            {

                //LogYuMin.LogWriter.GetWriter(LogYuMin.LogFile.Log).Write(GetType(), "GetOrderByOrdernumber", LogYuMin.LogStates.ERROR, ex);
          
            }
            finally
            {
                try
                {
                    reader.Close();
                    con.Close();
                }
                catch
                {
                }
            }
            return null;
        }
    }
}
